package com.baichang.taoshunda.controller.mobile;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.FootmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 2018/3/12.
 */
@Controller
@RequestMapping(ControllerConstants.FOOTMARK)
public class FootmarkController extends BaseMobileController {
    @Autowired
    private FootmarkService footmarkService;

    @RequestMapping("/findFootMark")
    public void findFootMark(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer userId = getInteger(json, "userId", 0);
                Integer nowPage = getInteger(json, "nowPage", 1);
                Integer pageSize = getInteger(json, "pageSize", 20);
                String key = getString(json, "key", "");
                return footmarkService.findFootMark(userId, nowPage, pageSize, key);
            }
        });
    }

    @RequestMapping("/deleteFootMark")
    public void deleteFootMark(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer footMarkId = getInteger(json, "footMarkId", 0);
                return footmarkService.deleteFootMark(footMarkId);
            }
        });
    }

    @RequestMapping("/deleteAllFootMark")
    public void deleteAllFootMark(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer userId = getInteger(json, "userId", 0);
                return footmarkService.deleteAllFootMark(userId);
            }
        });
    }

    @RequestMapping("/deleteSelectedFootMark")
    public void deleteSelectedFootMark(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                String footMarkId = getString(json, "footMarkId", "");
                return footmarkService.deleteSelectedFootMark(footMarkId);
            }
        });
    }
}
